package com.googlecode.garbagecan.dbtest.benchmark;

import java.io.File;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.List;

import org.apache.commons.io.FileUtils;

public class TestInsert {
	
	public static void main(String[] args) throws Exception {
		TestInsert ti = new TestInsert();
		ti.createTables();
		ti.dropTables();
	}
	
	private void createTables() throws Exception {
		String file = TestInsert.class.getResource("/com/googlecode/garbagecan/dbtest/benchmark/create.sql").getFile();
		List<String> sqls = FileUtils.readLines(new File(file));
		Connection conn = DBUtil.getConnection();
		for (String sql : sqls) {
			PreparedStatement ps = conn.prepareStatement(sql);
			ps.executeUpdate();
			ps.close();
		}
		conn.close();
	}
	
	private void dropTables() throws Exception {
		String file = TestInsert.class.getResource("/com/googlecode/garbagecan/dbtest/benchmark/drop.sql").getFile();
		List<String> sqls = FileUtils.readLines(new File(file));
		Connection conn = DBUtil.getConnection();
		for (String sql : sqls) {
			PreparedStatement ps = conn.prepareStatement(sql);
			ps.executeUpdate();
			ps.close();
		}
		conn.close();
	}
	
	public void batchInsert() {
		
	}
}

